<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%-- 
    Document   : users.jsp
    Created on : 19.11.2008, 15:33:27
    Author     : Cyclone
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<body>
    <script src="js/users.js" type="text/javascript"></script>

    <%@include file="systemMessage.jsp" %>

    <div id="box" class="rounded-divcascade">
        <div id="rightnow">
            <h3 class="reallynow">
                <c:choose><c:when test='<%= request.isUserInRole("admin")%>'>
                        <span>Пользователи</span>
                    </c:when><c:otherwise>
                        <span>Студенты</span>
                    </c:otherwise></c:choose>
                <c:if test='<%= request.isUserInRole("admin") || request.isUserInRole("tutor")%>'>
                    <a class="useradd" href="#addUser" onclick="document.getElementById('lastname').focus();">Добавить пользователя</a>
                </c:if>
                <br/>
            </h3>
        </div>
        <table width="100%">
            <thead>
                <tr>
                    <c:if test='<%= request.isUserInRole("admin")%>'>
                        <th width="30px"><a href="?sort=id">ID<c:if test='${param.sort == "id"}'><img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></c:if></a></th>
                            </c:if>
                    <th><a href="?sort=name">ФИО<c:if test='${param.sort == null || param.sort == "name"}'><img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></c:if></a></th>
                    <th width="150px"><a href="?sort=email">Email<c:if test='${param.sort == "email"}'><img src="img/icons/arrow_down_mini.gif" width="16" height="16" align="absmiddle" /></c:if></a></th>

                    <%-- <c:if test='<%= request.isUserInRole("tutor") %>'> --%>
                    <c:if test="${sessionScope.roles.tutor || sessionScope.roles.student}">
                        <th width="160px"><a href="#">Изучает курс</a></th>
                    </c:if>
                    <c:if test='<%= request.isUserInRole("admin")%>'>
                        <th width="70px">Роли</th>
                        <th width="70px">Регистрация</th>
                    </c:if>
                    <th width="60px">Операции</th>
                </tr>
            </thead>
            <tbody>

                <c:if test="${!empty userBeanList}">
                    <c:forEach var="userBean" items="${userBeanList}">
                        <c:set var="user" value="${userBean.userIdentity}" />
                        <tr>
                            <c:if test='<%= request.isUserInRole("admin")%>'>
                                <td class="a-center">${user.account}</td>
                            </c:if>
                            <td><a href="Profile?id=${user.account}" title="Профиль">${user.name}</a></td>
                            <td><a href="mailto:${user.login}" title="Отправить письмо">${user.login}</a></td>
                            <c:if test="${sessionScope.roles.tutor || sessionScope.roles.student}">
                                <td>
                                    <c:forEach items="${userBean.courseList}" var="course">
                                        <p style="padding: 0px;"><a href="Course?id=${course.id}" title="Редактировать курс">${course.title}</a></p>
                                    </c:forEach>
                                </td>
                            </c:if>
                            <c:if test='<%= request.isUserInRole("admin")%>'>
                                <td>

                                    <c:forEach var="profile" items="${user.account_1.profiles}">
                                        ${profile.profileType.name}
                                    </c:forEach>

                                </td>
                                <td>
                                    <c:forEach var="profile" items="${user.account_1.profiles}">
                                        <c:if test="${!empty profile.recordDate}">
                                            ${fn:substring(profile.recordDate,0,10)}
                                            <%--${profile.recordDate.year+1900}.${profile.recordDate.month+1}.${profile.recordDate.date}--%>
                                        </c:if>
                                    </c:forEach>
                                </td>
                            </c:if>
                            <td><center>
                                    <a href="Profile?id=${user.account}"><img src="img/icons/user.png" title="Профиль" width="16" height="16" /></a>
                                        <c:if test="${sessionScope.roles.admin || sessionScope.roles.tutor}">
                                        <a href="Curriculum?id=${user.account}"><img src="img/icons/user_edit.png" title="Учебный журнал" width="16" height="16" /></a>
                                        </c:if>
                                        <c:if test='<%= request.isUserInRole("admin")%>'>
                                        <a href="#" onclick="deleteUser(${user.account});"><img src="img/icons/user_delete.png" title="Удалить пользователя" width="16" height="16" /></a>
                                        </c:if>
                                </center>
                            </td>
                        </tr>

                    </c:forEach>
                </c:if>

            </tbody>
        </table>
        <div id="pager">
            <form action="Users" id="pagerForm" style="padding-top: 0px; padding-bottom: 0px;">
                Страница
                <c:if test="${!empty param.sort}">
                    <input type="hidden" name="sort" value="${param.sort}" />
                </c:if>
                <img src="img/icons/arrow_left.gif" onclick="pageTurn(-1);return false;" style="cursor: pointer;" />
                <input size="1" value="${page}" onchange='document.getElementById("pagerForm").submit();' type="text" name="page" id="page" />
                <img src="img/icons/arrow_right.gif" onclick="pageTurn(1);return false;" style="cursor: pointer; width: 16px; height: 16px;" />
                из ${totalPages} страниц | Показывать
                <select name="view" onchange="pagerSelectChange();">
                    <option<%= request.getAttribute("rowCount").equals(10) ? " selected" : ""%>>10</option>
                    <option<%= request.getAttribute("rowCount").equals(20) ? " selected" : ""%>>20</option>
                    <option<%= request.getAttribute("rowCount").equals(50) ? " selected" : ""%>>50</option>
                    <option<%= request.getAttribute("rowCount").equals(100) ? " selected" : ""%>>100</option>
                </select>
                на странице | Всего <strong>${totalRows}</strong> записей найдено
            </form>
        </div>
    </div>
    <br />

    <c:if test='${sessionScope.roles.admin || sessionScope.roles.tutor}'>
        <div id="box" class="rounded-divcascade">
            <c:choose><c:when test='<%= request.isUserInRole("admin")%>'>
                    <h3 class="reallynow" id="adduser"><a name="addUser">Новый пользователь</a></h3>
                </c:when><c:otherwise>
                    <h3 class="reallynow" id="adduser"><a name="addUser">Новый студент</a></h3>
                </c:otherwise>
            </c:choose>
            <form id="form" action="AddUserServlet" method="post" class="rounded-formcascade">
                <fieldset id="personal">
                    <legend>Информация</legend>
                    <label for="lastname">Фамилия : </label>
                    <input name="lastname" id="lastname" type="text"
                           tabindex="1" />
                    <br />
                    <label for="firstname">Имя : </label>
                    <input name="firstname" id="firstname" type="text"
                           tabindex="2" />
                    <br />
                    <label for="email">E-mail : </label>
                    <input name="email" id="email" type="text"
                           tabindex="3" />
                    <br />

                    <label for="pass">Пароль : </label>
                    <input name="pass" id="pass" type="password"
                           tabindex="4" onkeyup="checkPass();"/>
                    <br />
                    <label for="pass-2">Подтверждение : </label>
                    <input name="pass-2" id="pass-2" type="password"
                           tabindex="5" onkeyup="checkPass();" />
                    <br />
                    <label for="pass-2">Проверка : </label>
                    <input id="passcheck" type="text" style="color: gray;"
                           disabled />
                    <br />
                </fieldset>

                <c:if test='<%= request.isUserInRole("admin")%>'>
                    <c:choose><c:when test="${!empty typeList}">
                            <fieldset>
                                <legend>Группа</legend>
                                <table class="noBorder" style="width: 100%;">
                                    <tbody>
                                        <c:forEach items="${typeList}" var="type">
                                            <tr><td style="width: auto"><label for="group_${type.id}">${type.name} : </label></td>
                                                <td><input name="group_${type.id}" type="checkbox" style="width: auto" /></td></tr>
                                                </c:forEach>
                                    </tbody>
                                </table>
                            </fieldset>
                        </c:when><c:otherwise>
                            Список групп не получен
                        </c:otherwise>
                    </c:choose>
                </c:if>

                <c:if test='<%= request.isUserInRole("tutor")%>'>
                    <c:choose><c:when test="${!empty courseList}">
                            <fieldset>
                                <legend>Зачисление на курс</legend>
                                <label for="course">Курс : </label>
                                <select name="course">
                                    <c:if test="${sessionScope.roles.admin}">
                                        <option value="-1">Не зачислять</option>
                                    </c:if>
                                    <c:forEach items="${courseList}" var="course">
                                        <option value="${course.id}">
                                            ${course.curriculumLevel.title} : №${course.numeral} ${course.title}
                                        </option>
                                    </c:forEach>
                                </select>
                            </fieldset>
                        </c:when><c:otherwise>
                            Список курсов пуст
                        </c:otherwise>
                    </c:choose>
                </c:if>

                <div align="center">
                    <input id="button1" type="button" value="Сохранить" tabindex="7" onclick="save();" />
                    <input id="button2" type="reset" value="Очистить" tabindex="8"/>
                </div>
            </form>

        </div>
    </c:if>

    <script type="text/javascript">
        $(document).ready(function(){
            $("#liUsers").addClass("current");
            $('div#top-panel p').text('Зарегистрированные пользователи');
        });
    </script>
</body>

